﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;

namespace ACPLogAnalyzer
{
    /// <summary>
    /// Class to read and write all the properties used by the application to/from the registry
    /// </summary>
    class AppSettings
    {
        #region Declarations
        private string m_docRoot;
        private string m_logDir;
        #endregion

        #region Properties
        public string DocRoot
        {
            get
            {
                return m_docRoot;
            }
            set
            {
                m_docRoot = value;
            }
        }

        public string LogDir
        {
            get
            {
                return m_logDir;
            }
            set
            {
                m_logDir = value;
            }
        }
        #endregion

        #region Construction
        public AppSettings()
        {
            this.DocRoot = "";
            this.LogDir = "";
        }
        #endregion

        #region Read/Write Registry Methods
        public void ReadRegistry()
        {
            Microsoft.Win32.RegistryKey key;
            try
            {
                // Get -> HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Denny\ACP\WebServer
                key = Microsoft.Win32.Registry.LocalMachine.
                    OpenSubKey("Software", false).
                    OpenSubKey("Denny", false).
                    OpenSubKey("ACP", false).
                    OpenSubKey("WebServer", false);

                if (key != null)
                {
                    m_docRoot = key.GetValue("DocRoot") as string;
                    key.Close();
                }

                // Get -> HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Denny\ACP\UserData\local_user
                key = Microsoft.Win32.Registry.LocalMachine.
                    OpenSubKey("Software", false).
                    OpenSubKey("Denny", false).
                    OpenSubKey("ACP", false).
                    OpenSubKey("UserData", false).
                    OpenSubKey("local_user", false);

                if (key != null)
                {
                    m_logDir = key.GetValue("LogDir") as string;
                    key.Close();
                }
            }
            catch
            {
            }
        }

        #endregion
    }
}